clear
rng(23)

outer_counter = 1;
repeats = 5;
num_comps = 10;
num_moments = 5;
parpool('local',num_comps)

%%% REPEAT SIMULATION FOR DIFFERENT VALUES OF KAPPA WITH FIXED TAU.
%%% PARAMETERS FOR EACH ARE ESTIMATED USING THE GRID SEARCH FUNCTION IN
%%% run_annealing_para.m
for kappa = [0.5 0.4 0.3 0.2 0.1 0.01]
disp(kappa)
if kappa == 0.5
params = [0.1249   0.026   0.1299     1.538     6.574   kappa];
end
if kappa == 0.4
params = [0.1291   0.029    0.1616     1.538     6.69   kappa];
end
if kappa == 0.3
params = [0.1303   0.0296    0.1646     1.538     6.63   kappa];
end
if kappa == 0.2
params = [0.133   0.0304    0.1808     1.538     6.78   kappa];
end
if kappa == 0.1
params = [0.148   0.310    0.1994     1.538     6.87   kappa];
end
if kappa == 0.01
params = [0.1653   0.0344    0.2467     1.538     6.94   kappa];
end
iteration_data = zeros(1,num_moments);
counter=1;
while counter <= repeats
parfor computer_num = 1:num_comps
temp_data = steady_state_simulation_plots_counterfactuals(params);
iteration_data = iteration_data+temp_data'; 
end
counter = counter+1
end
iteration_data = iteration_data./(repeats*num_comps);
simulated_data_kappa = [simulated_data_kappa; kappa iteration_data(4)];
outer_counter = outer_counter+1
end

save('spillover_trade_moments.mat','simulated_data_kappa')

load('spillover_trade_moments.mat')


load('spillover_trade_moments.mat')
%%% PARTIAL SPILLOVER TRADE ELASTICITY
hold on
plot(simulated_data_kappa(:,1),simulated_data_kappa(:,2),'k','LineWidth',2.0)
axis([0 0.5 1 4])
xticks([0 0.1 0.2 0.3 0.4 0.5])
set(gcf,'color','white')
ax = gca
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
hold off

